# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/15 21:32
# @Author   : Robot-Zsj
"""
description:

i:
1,2,3,4,5,6,7,8,9
4
3

o:
13
"""


class Node:
    def __init__(self, val):
        self.val = val
        self.prev = None
        self.next = None


class CycleLink:
    def __init__(self, nums):
        self.head = None
        self.tail = None
        self.cur = None
        self.size = 0
        self.sum = 0

        for num in nums:
            self.add(num)

        if self.head is not None:
            self.head.prev = self.tail
            self.tail.next = self.head
            self.cur = self.head

    def add(self, val):
        node = Node(val)

        if self.size == 0:
            self.head = node
            self.tail = node
        else:
            self.tail.next = node
            node.prev = self.tail
            self.tail = node

        self.sum += val
        self.size += 1

    def remove(self):
        self.sum -= self.cur.val
        self.size -= 1

        prev = self.cur.prev
        next = self.cur.next

        prev.next = next
        next.prev = prev

        self.cur.prev = None

        self.cur.next = None

        self.cur = next

    def next(self):
        self.cur = self.cur.next


nums = list(map(int, input().split(",")))
jump = int(input())
left = int(input())


def sumOfLeft(nums, jump, left):
    link = CycleLink(nums)

    link.next()

    while link.size > left:
        zip_jump = jump % link.size
        for _ in range(zip_jump):
            link.next()
        link.remove()

    return link.sum


print(sumOfLeft(nums, jump, left))
